package com.nnxy.work_to_study.service.impl;

import com.nnxy.work_to_study.entity.Job;
import com.nnxy.work_to_study.mapper.JobMapper;
import com.nnxy.work_to_study.service.JobService;
import com.nnxy.work_to_study.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author @easily001
 * @since 2021-09-29
 */
@Service
public class JobServiceImpl implements JobService {
    @Autowired
    private JobMapper jobMapper;

    @Override
    public int addJob(Job job) {
        return jobMapper.addJob(job);
    }


    @Override
    public ResultUtil getJobList(String name, String projectId, Integer page, Integer limit) {
        Map map = new HashMap();
        map.put("page", (page - 1) * limit);
        map.put("limit", limit);
        map.put("name", name);
        map.put("projectId", projectId);
        List<Map> dbProductDict = jobMapper.getJobList(map);
        Integer count = jobMapper.getJobListCount(map);
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setCode(0);
        resultUtil.setCount(count);
        resultUtil.setData(dbProductDict);
        return resultUtil;
    }


    @Override
    public int deleteJob(Integer id) {
        return jobMapper.deleteJob(id);
    }

    @Override
    public int updateJob(Job job) {
        return jobMapper.updateJob(job);
    }


}
